<?php
/**
 * Created by PhpStorm.
 * User: 4399-1500
 * Date: 2018/4/11
 * Time: 14:51
 */

namespace models\Traits;
use ErrorMsg\Admin\ErrorTips;
use Yaf\Exception;
use Yaf\Session;
use Yaf\Registry;

trait UserTrait
{
    /**
     * @param $pwd             用户数据库密码
     * @param $vilidPwd         用户输入密码
     * @return bool|Exception
     */
    public function vilidataUser($pwd/*用户数据库密码*/,$vilidPwd/*用户输入密码*/){
        if (empty($pwd)) return new Exception('会员不存在','001');

        $password_invalid =$this->CheckPassword( $pwd,trim($vilidPwd)) ;
        if($password_invalid instanceof Exception)
            return $password_invalid;
        return $password_invalid;
    }

    public function checkPassword($pwd,$vilidPwd){
        $md5Pwd = md5(md5($vilidPwd).Registry::get('config')['salt']);
        return $pwd ===$md5Pwd;
    }

}